import { Component, NgModule } from '@angular/core';

let a: string;
let b: Array<number | string>;

//接口interface
interface person {
  first: string,
  last: string
}
function greet(p: person) {
  return p.first + p.last
}
greet({ first: 'ii', last: 'jj' })
// class
//基本用法
class Fo {
  //属性 方法 构造方法
  greeting: string;
  constructor(msg: string, readonly age: number) {
    // 属性方法啊·
    this.greeting = msg

  }
  foo() {
    return 'hooo' + this.greeting
  }
}
let foo = new Fo('nilll', 89)

// console.log(foo.foo(), foo.greeting);
//继承
class Animal {
  name: string
  private pri: string
  protected pro: string
  //父类有构造函数 子类必须调用之
  constructor(tn: string) {
    this.name = tn
    this.pri = tn
    this.pro = tn
  }
  move(disc: number = 0) {
    // console.log(`${this.name} move ${disc} ${this.pri}`);
  }
}

class Dog extends Animal {
  constructor(th: string) {
    //super调用父类构造函数
    super(th)
  }
  // 扩展
  bark() {
    // console.log('wwdog', this.name, this.pri);
    // console.log(this.pro);

  }
  move(dis = 89) { //overiding
    // console.log('run ');
    super.move(dis)

  }
  // move(a = 0, b?: number) {
  //   console.log(a + b);

  // }
}
const dog = new Dog('dog')
dog.bark()
dog.move(76)

// public privite protectd  readonly -- (声明或者构造赋值后) 
// 参数属性 同时定义并且初始化成员属性
// static 通过类名直接访问 静态成员
// 存取器 设置和获取带额外属性

class FFP {
  static Pi = '9090'

  static ffp(str = 9) {
    return str * str
  }
}
// console.log(FFP.Pi);
// console.log(FFP.ffp(89));
//getter setter
class Em {
  fullName = ''
  _ioio = 'ioio'
  get ioio() {
    return this._ioio
  }
  set ioio(val) {
    // console.log(this.fullName);

    this._ioio = val
  }

}
const e = new Em()
e.fullName = '99'

// 函数的可选参数 与默认值
function build(name: string = '909', last?: string) {
  // console.log(name);
}

build('ii')
build('ii', 'ii')
build()

// 范型 
function noGenerical(arg: number): number {
  return arg
}
function noG2(arg: any): any {
  return arg
}
//T成为类型变量 特殊变量 类型 不是值
function useGeneric<T>(arg: T): T {
  return arg
}

useGeneric<string>('ioio')
useGeneric(787)

// interface Result<T> {
//   success: boolean;
//   data?: T
// }
interface User {
  id: number;
  name: string
}
const r: Result<User> = { success: true, data: { id: 1, name: 'james' } }
//范型类
class Result<T>{
  constructor(public success: boolean, public data: T) { }
}

// 范型的约束
interface lengthWise {
  length: number
}
function useG<T extends lengthWise>(arg: T): T {
  // console.log(arg.length);
  return arg

}
useG({ length: 22, value: 112 })

//模块
// 模块的导出
// 具名导出 导入
import ss, { Host, add, Fooo, ooxx } from './myModule';
// console.log(ss);
// 接口的类不要同名

//装饰器decorator 包装器
// @NgModule()  工厂函数  NgModule({})(AppComponent)  快速配置

//ts 方法 重载
function over(s: string);
function over(s: number);
function over(s) {
  return s
}
//...  装饰器 元数据编程 
@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.scss']
})
export class AppComponent {
  title = 'aaagogog';
}
